package edu.sjsu.cs.GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import edu.sjsu.cs.security.ShuffleCipher;


public class EncodeShuffleCipherButton extends JButton
{ 
      public EncodeShuffleCipherButton(JTextField aTextfield,JTextField keyTextField)
      {
         super("Encode with Shuffle Cipher");
         TextField = aTextfield;
         KeyTextField = keyTextField;
         ActionListener listener = new ButtonListener();
         this.addActionListener(listener);
      }
      class ButtonListener implements ActionListener
      {
         public void actionPerformed(ActionEvent e)
         {
            try
            {
               Key = Integer.parseInt(KeyTextField.getText());
               ShuffleCipher encryption = new ShuffleCipher(Key);
               Label.setText(encryption.encode(TextField.getText()));
            }
            catch(Exception e1)
            {
               Label.setText("Please enter an positive integer smaller than "+Integer.MAX_VALUE+" .");
            }
         }
      }
      public void addLabel(JLabel aLabel)
      {
         Label = aLabel;
      }
      private JLabel Label;
      private JTextField TextField;
      private JTextField KeyTextField;

      private int Key;
}

